home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / source / jpegagasrc11.lha / jpegagasrc / ppm2aga / ppm2AGA.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-05  |  6.4 KB  |  279 lines

  1. /* ppm2AGA main module                */
  2. /* written 1993-94 by Günther Röhrich */
  3. /* This is version 1.4                */
  4.  
  5. #include <clib/exec_protos.h>
  6. #include <clib/intuition_protos.h>
  7. #include <clib/graphics_protos.h>
  8. #include <intuition/intuitionbase.h>
  9. #include <graphics/gfxbase.h>
  10. #include <libraries/iffparse.h>
  11. #include <iffp/ilbmapp.h>
  12. #include <dos/dos.h>
  13. #include <stdio.h>
  14. #include <stdarg.h>
  15. #include <string.h>
  16.  
  17. #ifndef __GNUC__
  18. #include <pragmas/intuition_pragmas.h>
  19. #include <pragmas/graphics_pragmas.h>
  20. #include <pragmas/exec_pragmas.h>
  21. #endif
  22.  
  23. #include "ppm2AGA.h"
  24.  
  25. #ifdef __GNUC__
  26. #include <signal.h>
  27. #define MYSTRCMP strcasecmp
  28. #define MYSTRNCMP strncasecmp
  29. #else
  30. #define MYSTRCMP strcmp
  31. #define MYSTRNCMP strncmp
  32. #endif
  33.  
  34.  
  35. /* externals used by this module */
  36.  
  37. extern int ppm2ilbm(char *PPMfile, ULONG Mode, int NumPlanes, ULONG MaxMem); 
  38. #ifdef AZTEC_C
  39. extern int Enable_Abort; /* Needed to disable default CTRL-C handling */
  40. #endif
  41.  
  42. /* globals defined in this module */
  43.  
  44. char  *ver = "\0$VER: ppm2AGA 1.4 (5.10.94)";
  45. struct Library *IntuitionBase = NULL;
  46. struct Library *GfxBase = NULL;
  47. struct Library *IFFParseBase = NULL;
  48. int floyd=0; /* indicates if FS-dithering should be used */
  49. char *ILBMfile;
  50. int ExactColor=0; /* indicates if shifting colors is allowed */
  51. int GfxEnable=0;  /* indicate if Gfx is enabled */
  52. int VGAenable=0;  /* indicate VGA-mode */
  53. int jpegAGA=0;    /* indicate that map-file should be created */
  54. ULONG SMR=0;      /* indicate that user has chosen a screenmode */
  55. ULONG SMR_DisplayID;  /* this variable contains later the DisplayID */
  56. ULONG SMR_NumPlanes;
  57. ULONG SMR_HAM;   
  58.  
  59. void PLError(char *ErrorString); /* prints the message, cleans up and quits */
  60. void PLExit(int returnvalue); /* cleans up and quits */
  61. void pm_message(char* format, ... );
  62. int AbortCheck(void);
  63. void PLProgress(ULONG Value, ULONG MaxValue);
  64.  
  65.  
  66. #ifdef __GNUC__
  67. int GCCabort=0;
  68. /* this is called when CTRL-C occurs */
  69. void GCCAbortHandler(void)
  70. {
  71.   GCCabort=1;
  72. }
  73. #endif
  74.  
  75. void PLUsage(void)
  76. {
  77.  PLError("Usage: ppm2AGA infile outfile [switches]\n"
  78.          "switches: -HAM8    use HAM8-conversion (default)\n"
  79.          "          -HAM6    use HAM6-conversion\n"
  80.          "          -CMAPn   use COLORMAP conversion with n bitplanes\n"
  81.          "          -E       use exact colors (only COLORMAP mode)\n"
  82.          "          -FS      enable Floyd-Steinberg dithering\n"
  83.          "          -Mx      load pictures up to size x into memory\n"
  84.          "          -2       enable 2-pass processing for HAM mode\n" 
  85.          "          -D       display picture during processing\n"
  86.          "          -VGA     use VGA screenmode\n"
  87.          "          -SMR     use screen mode requester\n"
  88.          "          -jpegAGA create colormap file for jpegAGA\n");
  89. }
  90.  
  91.  
  92. main(int argc, char *argv[])
  93. {
  94.  int Error;
  95.  int i;
  96.  ULONG Mode=HAM8;
  97.  int NumPlanes = 63;
  98.  int Pass = 1; /* 2-pass disabled by default */
  99.  ULONG MaxMem = 1000000;
  100.  
  101.  #ifdef AZTEC_C             /* Disable Aztec C CTRL-C handling */
  102.  Enable_Abort = 0;
  103.  #endif
  104.  #ifdef __GNUC__            /* Modify GNU C CTRL-C handling */
  105.  signal(SIGINT, GCCAbortHandler);
  106.  #endif
  107.  
  108.  puts("ppm2AGA V1.4 written by Günther Röhrich.");
  109.  
  110.  /* remove the comments for beta versions */
  111.  /*  puts("Preliminary version. DO NOT SPREAD IT!");  */
  112.  
  113.  
  114.  /* Open all the libraries we need */
  115.  
  116.  if(!(IntuitionBase = OpenLibrary((UBYTE *)"intuition.library", 33)))
  117.    PLError("Can't open intuition.library V33 or higher.\n");
  118.  
  119.  if(!(GfxBase = OpenLibrary((UBYTE *)"graphics.library",33)))
  120.    PLError("Can't open graphics.library V33 or higher.\n");
  121.  
  122.  /* iffparse.library V37 works also with Kickstart 1.2/1.3 */
  123.  
  124.  if(!(IFFParseBase = OpenLibrary((UBYTE *)"iffparse.library",36)))
  125.    PLError("Can't open iffparse.library V36 or higher.\n");
  126.  
  127.  if(argc < 3) PLUsage();
  128.  
  129.  for(i=3; i<argc; i++)
  130.  {
  131.    #ifndef __GNUC__
  132.    strupr(argv[i]);
  133.    #endif
  134.    if(!MYSTRNCMP(argv[i], "-HAM8", 5))
  135.    {
  136.      Mode = HAM8;
  137.      NumPlanes = 63;
  138.    }
  139.    else if(!MYSTRNCMP(argv[i], "-HAM6", 5))
  140.    {
  141.      Mode = HAM6;
  142.      NumPlanes = 15;
  143.    }
  144.    else if(!MYSTRNCMP(argv[i], "-CMAP", 5))
  145.    {
  146.      Mode = COLORMAP;
  147.      NumPlanes = (int)strtoul(&argv[i][5], NULL, 0);
  148.      if(NumPlanes < 1 || NumPlanes > 8)
  149.      PLError("Only 1 to 8 planes allowed.\n");
  150.    }
  151.    else if(!MYSTRNCMP(argv[i], "-M", 2))
  152.    {
  153.      MaxMem = strtoul(&argv[i][2], NULL, 0);
  154.    }
  155.    else if(!MYSTRNCMP(argv[i], "-FS", 3))
  156.    {
  157.      floyd = 1;
  158.    }
  159.    else if(!MYSTRNCMP(argv[i], "-E", 2))
  160.    {
  161.      ExactColor = 1;
  162.    }
  163.    else if(!MYSTRNCMP(argv[i], "-D", 2))
  164.    {
  165.      GfxEnable = 1;
  166.    }
  167.    else if(!MYSTRNCMP(argv[i], "-2", 2))
  168.    {
  169.      Pass = 0;
  170.    }
  171.    else if(!MYSTRNCMP(argv[i], "-VGA", 4))
  172.    {
  173.      VGAenable = 1;
  174.    }
  175.  
  176.    else if(!MYSTRNCMP(argv[i], "-SMR", 4))
  177.    {
  178.      SMR = 1;
  179.    }
  180.  
  181.    else if(!MYSTRNCMP(argv[i], "-jpegAGA", 8))
  182.    {
  183.      jpegAGA = 1;
  184.    }
  185.    else PLUsage();
  186.    if( (jpegAGA == 1) && (Pass == 0 || Mode != HAM8)) PLUsage(); 
  187.  }    
  188.  
  189.  
  190.  if(SMR)
  191.  {
  192.    if(ChooseScreenMode()) PLError("No screen mode selected.\n");
  193.    if(SMR_HAM)
  194.    {
  195.      if(SMR_NumPlanes == 8)
  196.      {
  197.        Mode = HAM8;
  198.        NumPlanes = 63;
  199.      }
  200.      else
  201.      {
  202.        Mode = HAM6;
  203.        NumPlanes = 15;
  204.      }
  205.    }
  206.    else
  207.    {
  208.      Mode = COLORMAP;
  209.      NumPlanes = SMR_NumPlanes;
  210.    } 
  211.  }
  212.  
  213.  ILBMfile = argv[2];
  214.  if(Mode == HAM8 || Mode == HAM6) NumPlanes = NumPlanes + Pass;
  215.  
  216.  Error = ppm2ilbm(argv[1], Mode, NumPlanes, MaxMem);
  217.  
  218.  /* if(Error) pm_message("Error, no picture created.\n"); */
  219.  
  220.  PLExit(Error);  
  221. }
  222.  
  223. void PLError(char *ErrorString)
  224. {
  225.  pm_message(ErrorString);
  226.  PLExit(10);
  227. }
  228.  
  229.  
  230.  
  231.  
  232. /* NOTE: if you want to implement a GUI you only have to */
  233. /* change the functions below, not the complete program  */
  234.  
  235.  
  236. /* this is called on exit */
  237.  
  238. void PLExit(int returnvalue)
  239. {
  240.  if(IntuitionBase) CloseLibrary(IntuitionBase);
  241.  if(GfxBase)       CloseLibrary(GfxBase);
  242.  if(IFFParseBase)  CloseLibrary(IFFParseBase);
  243.  exit(returnvalue);
  244. }
  245.  
  246.  
  247. /* this is called to see if we must abort */
  248.  
  249. int AbortCheck(void)
  250. {
  251.  #ifndef __GNUC__
  252.  return SetSignal(0L,0L)&SIGBREAKF_CTRL_C;
  253.  #else
  254.  return GCCabort;
  255.  #endif 
  256. }
  257.  
  258.  
  259. /* this is called for progress reports */
  260. /* not called in this version */
  261.  
  262. void PLProgress(ULONG Value, ULONG MaxValue)
  263. {
  264.  /* we do nothing special right now */
  265.  printf("\015Progress: %5.2f%%", Value * 100.0 / (MaxValue + 1));
  266. }
  267.  
  268.  
  269. /* this is called when a message must be printed */
  270.  
  271. void pm_message(char* format, ... )
  272. {
  273.   va_list args;
  274.  
  275.   va_start( args, format );
  276.   vprintf(format, args );
  277.   va_end( args );
  278. }
  279.